package com.lemeng.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.lemeng.entity.PageResult;
import com.lemeng.entity.Result;
import com.lemeng.entity.SchoolVo;
import com.lemeng.pojo.School;
import com.lemeng.pojo.SchoolType;
import com.lemeng.service.SchoolService;
import com.lemeng.service.SchoolTypeService;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("school")
public class SchoolController {


    @Reference
    SchoolService schoolService;


    @Reference
    SchoolTypeService schoolTypeService;

    @GetMapping("findAllSchoolType")
    public List<SchoolType> findAllSchoolType(){
        return schoolTypeService.findAll();
    }

    @GetMapping("selectCountInfo")
    public List<SchoolVo> selectCountInfo() {
        return schoolService.selectCountInfo();
    }

    @GetMapping("findAll")
    public List<School> findAll(){
        return schoolService.findAll();
    }

    @GetMapping("findPage")
    public PageResult<School> findPage(Integer page, Integer size) {
        return schoolService.findPage(page,size);
    }

    @PostMapping("findList")
    public List<School> findList(@RequestBody Map<String, Object> serchMap) {
        return schoolService.findList(serchMap);
    }
    @PostMapping("findPage")
    public PageResult<SchoolVo> findPage(Integer page, Integer size, @RequestBody SchoolVo schoolVo) {
        return schoolService.findPage(page,size,schoolVo);
    }
    @GetMapping("findById")
    public School findById(@RequestParam Integer id) {
        return schoolService.findById(id);
    }

    @PostMapping("add")
    public Result add(@RequestBody School school) {
        schoolService.add(school);
        return new Result();
    }
    @PostMapping("update")
    public Result update(@RequestBody School school) {
        schoolService.update(school);
        return new Result();
    }

    @GetMapping("delete")
    public Result delete(Integer id) {
        schoolService.delete(id);
        return new Result();
    }
    @GetMapping("deleteAll")
    public Result delete(String ids) {

        String[] split = ids.split(",");
        for (String id : split) {
            schoolService.delete(Integer.parseInt(id));
        }


        return new Result();
    }


}
